package org.spring.springboot.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.spring.springboot.result.Result;
import org.spring.springboot.util.CreateQR;
import org.springframework.web.bind.annotation.*;


import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

@RestController
@CrossOrigin
@Api(tags ="二维码")
@RequestMapping("/qr")
public class QR {

    @ApiOperation("生成二维码")
    @GetMapping("/generate")
    public Result QrGenerate(){
        String localDir = "d:/qr"+new SimpleDateFormat("/yyyy/MM/dd/").format(new Date());
        File dirFile = new File(localDir);
        if(!dirFile.exists()){
            dirFile.mkdirs();
        }
        UUID uuid = UUID.randomUUID();
        String filename = localDir+uuid+".png";
        String url = "http://www.bai.com";
        CreateQR.make(120, 120, url, filename);
        return Result.newSuccessResult(filename);
    }
}
